package com.hu.ta.assignment5.beans;

import java.util.HashMap;
import java.util.Map;

public abstract class Table<V, C, R> {
	protected V values[];
	protected Map<C, Integer> columnNames;
	protected Map<R, Integer> rowNames;

	protected Table(C columns[], R rows[]) {
		columnNames = new HashMap<C, Integer>();
		rowNames = new HashMap<R, Integer>();

		int i = 0;
		for (C token : columns) {
			columnNames.put(token, i++);
		}

		for (R tag : rows) {
			rowNames.put(tag, i++);
		}
	}

	protected void setValue(int i, int j, V v) {
		if (i * columnNames.size() + j < values.length) {
			values[i * columnNames.size() + j] = v;
		}
	}

	public V getValue(int col, int row) {
		return values[col * columnNames.size() + row];
	}

	public V getValue(C col, R row) {
		return getValue(columnNames.get(col), rowNames.get(row));
	}
}
